from flask import Flask, jsonify, abort, request
from flask import Blueprint, render_template, redirect
from controller.BooksController import BooksController

books = Blueprint('books', __name__)

from middleware.check import Check


# books类路由接口文件


# 获取books列表 接口
@books.route('/', methods=['GET'])
#
# token鉴权，用于判断用户身份
@Check.checkToken
#
# 获取books列表
def getBookFilter():
    return jsonify(BooksController.getBookFilter())

#
# 通过 id 获取book信息
@books.route('/<int:id>', methods=['GET'])
def getBookById(id):
    return jsonify(BooksController.getBookById(id))

#
# 新增新的 book 信息
@books.route('/', methods=['POST'])
def create_task():
    return jsonify(BooksController.addBook(request.form))

#
# 通过id更新 book信息
@books.route('/<int:id>', methods=['PUT'])
def update_book(id):
    return jsonify(BooksController.updateBookById(id))

#
# 通过id删除 book信息
@books.route('/<int:id>', methods=['DELETE'])
def delete_task(id):
    return jsonify(BooksController.deleteBookById(id))
